package com.ytjj.qmyx.users.service.impl;

import com.ytjj.qmyx.users.mapper.SmsToolEnterPhoneMapper;
import com.ytjj.qmyx.users.model.SmsToolEnterPhone;
import com.ytjj.qmyx.users.model.SmsToolEnterPhoneExample;
import com.ytjj.qmyx.users.service.SmsToolEnterPhoneService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
@RefreshScope
public class SmsToolEnterPhoneServiceImpl implements SmsToolEnterPhoneService {
    @Resource
    private SmsToolEnterPhoneMapper smsToolEnterPhoneMapper;

    @Override
    public int save(SmsToolEnterPhone record) {
        return smsToolEnterPhoneMapper.insertSelective(record);
    }

    @Override
    public SmsToolEnterPhone getByPhone(String phone) {
        SmsToolEnterPhoneExample example = new SmsToolEnterPhoneExample();
        example.createCriteria().andPhoneEqualTo(phone);
        example.setOrderByClause("id desc");
        List<SmsToolEnterPhone> records = smsToolEnterPhoneMapper.selectByExample(example);
        if (CollectionUtils.isEmpty(records)) {
            return null;
        }
        return records.get(0);
    }
}
